/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.chl.niclun.projectwebshop.nbp;

import edu.chl.niclun.projectwebshop.nbp.Entities.Movie;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

/**
 *BackingBean for the RightMenu
 * @author niclas
 */
@ManagedBean(name="RightMenuBackingBean")
@RequestScoped
public class RightMenuBackingBean {
    
    // the cart
    private Map<Movie, Integer> cart;
    private int count;
    private int totalCost;
    private int totCostIncShipping;
    private int shippingCost;
    
    
    /** Creates a new instance of RightMenuBackingBean */
    public RightMenuBackingBean() {
    }
    
    public Map<Movie, Integer> getCart() {
        return cart;
    }
    
    public void setCart(Map<Movie, Integer> cart) {
        this.cart = cart;
    }
    
    public int getCount() {
        return count;
    }
    
    public void setCount(int count) {
        this.count = count;
    }
    
    public int getTotalCost() {
        return totalCost;
    }
    
    public void setTotalCost(int totalCost) {
        this.totalCost = totalCost;
    }
    
    public int getShippingCost() {
        return shippingCost;
    }
    
    public void setShippingCost(int shippingCost) {
        this.shippingCost = shippingCost;
    }
    
    public int getTotCostIncShipping() {
        return totCostIncShipping; 
    }
    
    public void setTotCostIncShipping(int totCostIncShipping) {
        this.totCostIncShipping = totCostIncShipping;
    }
    //create a tostring representation of the movie
    public String getMovieString(Movie m) {
        StringBuilder builder = new StringBuilder();
        builder.append(getFixedLengthMovieTitle(m));
        return builder.toString();
    }
    //make the movie-string to a correct length
    public String getFixedLengthMovieTitle(Movie m) {
        String title = m.getTitle();
        if(title.length() > 10)
            title = title.substring(8) + "...";
        else if(title.length() < 10)
            title += "<p:spacer width: " + (10-title.length());
        
        title += "<p:spacer width: 2";
        
        return title;
    }
}
